//
//  AssetsTableViewCell.m
//  Youhuiju
//
//  Created by liuovyue on 16/7/26.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "AssetsTableViewCell.h"
#import "OrderformCollectionViewCell.h"
#import "AssetsTwoController.h"
#import "CouponViewController.h"
#import "ViewNavigationBar.h"

@interface AssetsTableViewCell()<UICollectionViewDelegate, UICollectionViewDataSource>



@property (weak, nonatomic) IBOutlet UICollectionView *collectionAsseset;
@property (nonatomic, strong)NSArray *arr;//放栏目名字

@property (strong, nonatomic) IBOutlet UIButton *buttonGiftCard;//联名卡
@property (strong, nonatomic) IBOutlet UILabel *lableMyAssets;//顶部标题

@property (nonatomic, strong)NSArray *arrNumber;//放数字的数组

//我的资产图标

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsImageLead;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsImageWidth;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsImageHeight;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsImageTop;
//我的资产
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assestI;//宽
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsHeight;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsTop;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *assetsLead;
//联名卡
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cardLead;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cardTrail;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cardTop;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cardBot;

//collection
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *collectionTop;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *collectionBot;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *colletcionTrail;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *collectionLead;

@property (strong, nonatomic) IBOutlet UIButton *buttonCard;

@property (strong, nonatomic) IBOutlet UILabel *labelAssests;




@end

@implementation AssetsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
   
    self.labelAssests.font = [UIFont systemFontOfSize:17*FitH];
    
    
    self.buttonCard.tintColor = [UIColor colorWithHexString:@"999999"];
    self.buttonCard.alpha = 0 ;
    self.buttonCard.titleLabel.font = [UIFont systemFontOfSize:14*FitW];
    self.arr = @[@"   优惠券",@"       积分",@" ",@" ",@" "];
    
    self.collectionAsseset.scrollEnabled = NO;
    self.collectionAsseset.delegate = self;
    self.collectionAsseset.dataSource = self;
    [self.collectionAsseset registerNib:[UINib nibWithNibName:@"OrderformCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"OrderformCollectionViewCell"];
    
    self.arrNumber = @[@"",@"     0",@"",@"",@""];
    
    
    self.buttonGiftCard.tintColor = [UIColor colorWithHexString:@"999999"];
    
    //我的资产图标
    self.assetsImageTop.constant = 1*FitH;
    self.assetsImageLead.constant = 7*FitW;
    self.assetsImageWidth.constant = 23*FitW;
    self.assetsImageHeight.constant = 22*FitH;
    
    //我的资产
    self.assetsTop.constant = 6*FitH;
    self.assetsHeight.constant = 17*FitH;
    self.assestI.constant = 68*FitW;
    self.assetsLead.constant = 16*FitW;
    
    //卡牌
    self.cardBot.constant = 8*FitH;
    self.cardTop.constant = 8*FitH;
    self.cardLead.constant = 138*FitW;
    self.cardTrail.constant = 8*FitW;
    
    //collection
    self.collectionBot.constant = -8*FitH;
    self.collectionTop.constant = 8*FitH;
    self.collectionLead.constant = -9;
    self.colletcionTrail.constant = -9;
    
    
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    OrderformCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OrderformCollectionViewCell" forIndexPath:indexPath];
    //cell.backgroundColor = [UIColor yellowColor];
    cell.labelCollectionCellOrder.text = [self.arr objectAtIndex:indexPath.row];
    cell.labelCollectionCellOrder.font = [UIFont systemFontOfSize:13*FitH];
    cell.labelCollectionCellOrder.textAlignment = NSTextAlignmentCenter;
    if (indexPath.row == 0) {
        cell.imageCollectionCellOrder.image = [UIImage imageNamed:@"ljzyouhuiquan"];
        
    }else {
        cell.imageCollectionCellOrder.alpha = 0;
        
    }
    cell.labelCollectionCellOrder.textColor = [UIColor colorWithHexString:@"333333"];
    cell.cellMoney.text = [self.arrNumber objectAtIndex:indexPath.row];
    cell.cellMoney.textAlignment = NSTextAlignmentCenter;
    return cell;
    
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(75 * FitW, 75 * FitH);
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.row ==0) {
     
        CouponViewController *coupon = [[CouponViewController alloc]init];
        id object = [self nextResponder];
        while (![object isKindOfClass:[UIViewController class]]&&object != nil) {
           
            
            object = [object nextResponder];
            
        }
        UIViewController *vc = (UIViewController *)object;
        [vc.navigationController pushViewController:coupon animated:YES];
        
        
        
        
        
        //vertie.labelTitle.text = @"优惠券";
    }else{
        
        AssetsTwoController *vertie = [[AssetsTwoController alloc]initWithNibName:@"AssetsTwoController" bundle:nil];
        vertie.labelTitle = [[UILabel alloc]init];
        
        id object = [self nextResponder];
        while (![object isKindOfClass:[UIViewController class]]&&object != nil) {
            
            object = [object nextResponder];
            
            
        }
        UIViewController *vc = (UIViewController *)object;
        vc.tabBarController.tabBar.hidden = YES;
        [vc.navigationController pushViewController:vertie animated:YES];
        vertie.labelTitle.text = @"积分";
    }
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
